/*
* Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
*
* Oracle is a registered trademarks of Oracle Corporation and/or its affiliates.
*
* This software is the confidential and proprietary information of
* Oracle Corporation.  You shall not disclose such confidential and
* proprietary information and shall use it only in accordance with the
* terms of the license agreement you entered into with Oracle.
*
* This notice may not be removed or altered.
*/
using Tangosol.IO.Pof;

namespace Examples
{
    public class ContactInfo : IPortableObject
    {
        #region Fields

        private string name;
        private string street;
        private string city;
        private string state;
        private string zip;

        #endregion

        #region Constructors

        public ContactInfo()
        { }

        public ContactInfo(string name, string street, string city, string state, string zip)
        {
            Name   = name;
            Street = street;
            City   = city;
            State  = state;
            Zip    = zip;
        }

        #endregion

        #region Properties

        public string Name
        {
            get {return name;}
            set {name = value;}
        }

        public string Street
        {
            get { return street; }
            set { street = value; }
        }

        public string City
        {
            get { return city; }
            set { city = value; }
        }

        public string State
        {
            get { return state; }
            set { state = value; }
        }

        public string Zip
        {
            get { return zip; }
            set { zip = value; }
        }

        #endregion

        #region GetHashCode, Equals, and ToString

        public override int GetHashCode()
        {
            return name == null ? 0 : name.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return true;
            }

            ContactInfo contactInfo = obj as ContactInfo;
            return contactInfo != null                &&
                   Equals(Name,   contactInfo.Name)   &&
                   Equals(Street, contactInfo.Street) &&
                   Equals(City,   contactInfo.City)   &&
                   Equals(State,  contactInfo.State)  &&
                   Equals(Zip,    contactInfo.Zip);
        }

        public override string ToString()
        {
            return "ContactInfo("
                + "Name="     + Name
                + ", Street=" + Street
                + ", City="   + City
                + ", State="  + State
                + ", Zip="    + Zip
                + ')';
        }

        #endregion

        #region IPortableObject

        public void ReadExternal(IPofReader reader)
        {
            Name   = reader.ReadString(0);
            Street = reader.ReadString(1);
            City   = reader.ReadString(2);
            State  = reader.ReadString(3);
            Zip    = reader.ReadString(4);
        }

        public void WriteExternal(IPofWriter writer)
        {
            writer.WriteString(0, Name);
            writer.WriteString(1, Street);
            writer.WriteString(2, City);
            writer.WriteString(3, State);
            writer.WriteString(4, Zip);
        }

        #endregion
    }
}
